package sv.gob.mh.dgii.dao.ed;

import java.util.List;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import sv.gob.mh.dgii.dao.hibernate.HibernateDaoImpl;
import sv.gob.mh.dgii.model.EdDatoF11;
import sv.gob.mh.dgii.model.EdDatoF11Id;

@Repository
public class EdDatoF11DaoImpl extends HibernateDaoImpl implements EdDatoF11Dao {

    private static String NIT = "id.nit";
    private static String EFISCAL = "id.fafiscal";
    private static String FOLIO = "nfolio";
    private static String FACTUALIZADO = "factualizado";

    public EdDatoF11DaoImpl() {
        super(EdDatoF11.class);
    }

    public EdDatoF11 findByEdDatoF11Id(EdDatoF11Id id) {
        EdDatoF11 ret = null;
        if (id != null
                && id.getFafiscal() != null && !id.getFafiscal().trim().equals("")
                && id.getNit() != null && !id.getNit().trim().equals("")) {
            Query q = getSessionFactory().getCurrentSession().createQuery("SELECT o FROM EdDatoF11 o WHERE o.id.nit=:nit AND o.id.fafiscal=:fafiscal ");
            q.setParameter("nit", id.getNit().trim());
            q.setParameter("fafiscal", id.getFafiscal().trim());

            List<EdDatoF11> list = q.list();
            if (list != null && !list.isEmpty()) {
                ret = list.get(0);
            }
        }
        return ret;
    }

    @Override
    public void updateEstadoWithProcedure(String nit, String periodo) throws Exception {
        String sql = "call PKG_EDA_UTILITARIOS.pr_actualiza_renta_web(?, ?)";
        Object[] params = new Object[]{nit, periodo};
        executeProcedure(sql, params);
    }


}